package com.tesserate.pmt;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.SwingUtilities;

import com.tesserate.game.api.fs.ResourceManager;
import com.tesserate.game.api.ui.FullScreenDevice;
import com.tesserate.game.api.ui.GraphicsObjects;

public class BlindManagerLobby extends GraphicsObjects {
	private static final long serialVersionUID = 6580028435892857517L;
	private static final int MAXIMO_BLINDS = 40;
	private static BlindManagerLobby instance;
	private Font font = new Font("Arial Black", Font.PLAIN, 16);
	private Color color = new Color(255, 223, 216);
	private Label[][] blindsManager = new Label[MAXIMO_BLINDS][5];

	MouseAdapter mouseListener = new MouseAdapter() {
		public void mousePressed(MouseEvent e) {
			int shift = e.isShiftDown() ? 10 : 1;
			int ctrl = e.isControlDown() ? 100 : 1;
			int alt = e.isAltDown() ? 1000 : 1;
			int fator = shift * ctrl * alt;
			if (SwingUtilities.isLeftMouseButton(e)) {
				((Label) (e.getSource())).addValor(fator);
				((Label) (e.getSource())).repaint();
			} else {
				((Label) (e.getSource())).addValor(-fator);
				((Label) (e.getSource())).repaint();
			}
		}
	};

	public static BlindManagerLobby getInstance() {
		if (BlindManagerLobby.instance == null) {
			BlindManagerLobby.instance = new BlindManagerLobby();
		}
		return BlindManagerLobby.instance;
	}

	private BlindManagerLobby() {
		int x = 0;
		int y = 0;
		int minis[] = { 25, 50, 75, 100, 150, 200, 300, 500, 600, 800,  
				1000, 1200, 1500, 2000, 2500, 3000, 4000, 5000, 6000, 8000, 
				10000, 15000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 
				100000, 150000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000 };
		int antes[] = { 0, 0, 0, 0, 0, 0, 0, 50, 50, 50,
						100,100,150,200,250,300,400,500,500,500,
						1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,
						20000,30000,40000,50000,60000,70000,80000,90000,100000,20000 };
		
		for (int i = 0; i < MAXIMO_BLINDS; i++) {
			y = 96 + ((i % 20) * 25);
			x = 75 + (i < 20 ? 0 : 380);

			Label rodada = new Label(i + 1, x, y, font, color);
			Label mini = new Label(minis[i], x + 85, y, font, color);
			mini.addMouseListener(mouseListener);
			mini.setValorMaximo(9999999);
			Label blind = new Label(minis[i] * 2, x + 170, y, font, color);
			blind.addMouseListener(mouseListener);
			blind.setValorMaximo(9999999);
			Label ante = new Label(antes[i], x + 255, y, font, color);
			ante.addMouseListener(mouseListener);
			ante.setValorMaximo(9999999);
			Label tempo = new Label(20, x + 315, y, font, color);
			tempo.addMouseListener(mouseListener);

			Container contentPane = FullScreenDevice.getInstance().getMainFrame().getContentPane();
			contentPane.add(rodada);
			contentPane.add(mini);
			contentPane.add(blind);
			contentPane.add(ante);
			contentPane.add(tempo);
			blindsManager[i][0] = rodada;
			blindsManager[i][1] = mini;
			blindsManager[i][2] = blind;
			blindsManager[i][3] = ante;
			blindsManager[i][4] = tempo;
		}
		posicao.x = 0;
		posicao.y = 0;
	}

	public void init() {

	}

	@Override
	public void render(Graphics2D g) {
		if (BlindManagerLobby.getInstance().isVisivel()) {
			paint(g);
			for (int i = 0; i < MAXIMO_BLINDS; i++) {
				for (int j = 0; j < 5; j++) {
					blindsManager[i][j].render(g);
				}
			}
		}
	}

	public void update(long elapsedTime) {

	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		g.drawImage(ResourceManager.getImageResource("blinds").getImage(), getX(), getY(), null);
	}

	public Label[][] getBlindsManager() {
		return blindsManager;
	}

	public void setBlindsManager(Label[][] blindsManager) {
		this.blindsManager = blindsManager;
	}
}
